#
# led   
#
import RPi.GPIO as GPIO
import time 
import threading 

LEFT_LED = 7  # gpio 7
RIGHT_LED = 40   # gpio 21

def init_led():
    GPIO.setup(LEFT_LED, GPIO.OUT)
    GPIO.setup(RIGHT_LED, GPIO.OUT)
    for i in range(5):
        GPIO.output(LEFT_LED, GPIO.LOW)
        GPIO.output(RIGHT_LED, GPIO.LOW)
        time.sleep(0.2)
        GPIO.output(LEFT_LED, GPIO.HIGH)
        GPIO.output(RIGHT_LED, GPIO.HIGH)
        time.sleep(0.2)

def led_go():
    GPIO.output(LEFT_LED, GPIO.HIGH)
    GPIO.output(RIGHT_LED, GPIO.HIGH)

def led_turn_right():
    GPIO.output(LEFT_LED, GPIO.HIGH)
    GPIO.output(RIGHT_LED, GPIO.LOW)

def led_turn_left():
    GPIO.output(LEFT_LED, GPIO.LOW)
    GPIO.output(RIGHT_LED, GPIO.HIGH)

def led_stop():
    GPIO.output(LEFT_LED, GPIO.LOW)
    GPIO.output(RIGHT_LED, GPIO.LOW)

# 暂时不处理 -后退闪烁-需要线程
def led_back_worker():
    while True:
        GPIO.output(LEFT_LED, GPIO.LOW)
        GPIO.output(RIGHT_LED, GPIO.LOW)
        time.sleep(0.2)
        GPIO.output(LEFT_LED, GPIO.HIGH)
        GPIO.output(RIGHT_LED, GPIO.HIGH)
        time.sleep(0.2)

def led_back():
    #led_back_thread = threading.Thread(target=led_back_worker,daemon=True)
    #led_back_thread.start()
    for i in range(5):
        GPIO.output(LEFT_LED, GPIO.LOW)
        GPIO.output(RIGHT_LED, GPIO.LOW)
        time.sleep(0.2)
        GPIO.output(LEFT_LED, GPIO.HIGH)
        GPIO.output(RIGHT_LED, GPIO.HIGH)
        time.sleep(0.2)
  